#!/bin/bash -

dir=$(dirname $0)
dir=$(cd $dir; pwd)

echo project directory is : $dir
echo


# rosPack=$(dpkg -l | grep ros-kinetic-rosbridge-server | grep -v "grep")


# if [ -z "$rosPack" ]
# then
# 	sudo apt-get install ros-kinetic-rosbridge-server
# fi

if [ ! -d ${dir}/build ]
then
	mkdir ${dir}/build
	cd ${dir}/build/
	cmake ..
	make

	cd ${dir}
fi

source ${dir}/build/devel/setup.bash

rosProcess=$(ps -aux | grep roscore | grep -v "grep" | awk '{print $2}')

if [ -z "$rosProcess" ]
then
	gnome-terminal --geometry=80x24 -x bash -c "roscore"
	sleep 1
	echo
fi

# roslaunchProcess=$(ps -aux | grep roslaunch | grep -v "grep" | awk '{print $2}')

# if [ -z "$roslaunchProcess" ]
# then
# 	gnome-terminal --geometry=80x30+960+0 -x bash -c "source ${dir}/build/devel/setup.bash; roslaunch rosbridge_server rosbridge_websocket.launch"
# 	sleep 1
# 	echo
# fi


sleep 1

# gnome-terminal --geometry=80x30+960+0 -x bash -c "firefox ${dir}/html/example.html"
gnome-terminal --geometry=80x30+960+0 -x bash -c "source ${dir}/build/devel/setup.bash; ${dir}/build/devel/lib/rosmsg/tank"

sleep 1
echo "send gps routes"
./send_route.py
echo


echo "enter any key to exit all programs"
read

# pkill roslaunch
pkill roscore
pkill tank


